package com.dilidili.service.impl;

import com.dilidili.mapper.VideoMapper;
import com.dilidili.service.IVideoService;
import com.domain.Video;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @PackgeName: com.dilidili.service.impl
 * @ClassName: VideoService
 * @Author: 零
 * Date: 2022/4/9 10:40
 * project name: spring-cloud-mybilibli
 * @Version:
 * @Description:
 */
@Service
public class VideoService implements IVideoService {

    /**
     * 视频SQL接口
     */
    @Autowired
    private VideoMapper videoMapper;

    /**
     * 查询用户的视频量
     *
     * @param userId 用户id
     * @return
     */
    @Override
    public Integer playCounts(Integer userId) {
        Integer videoState = 1;
        return videoMapper.playCounts(userId, videoState);
    }

    /**
     * 用户发布的视频数据
     *
     * @param userId   用户id
     * @param pageNum  当前第几页
     * @param pageSize 当前页有几条数据
     * @return
     */
    @Override
    public PageInfo<Map> queryUserId(Integer userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map> list = videoMapper.queryUserId(userId, 1);
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * @param userId 用户id
     * @return
     */
    @Override
    public List<Map<String, Object>> bigzoneByUserCount(Integer userId) {
        return videoMapper.bigzoneByUserCount(userId, 1);
    }

    /**
     * 查询用户发布视频
     * @param userId 用户id
     * @param bigzoneName 分区名称
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Map> synthesizeQuery(Integer userId, String bigzoneName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map> list = videoMapper.synthesizeQuery(userId, 1,bigzoneName);
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 根据用户点击量倒序
     * @param userId 用户id
     * @param bigzoneName 类型名称
     * @param pageNum 分页
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Map> synthesizeQueryDesc(Integer userId, String bigzoneName, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map> list = videoMapper.synthesizeQueryDesc(userId, 1,bigzoneName);
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 用户收藏的视频
     * @param userId 用户id
     * @param pageNum 分页
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Map<String, Object>> collectvideoUserById(Integer userId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list = videoMapper.collectvideoUserById(userId, 1);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 视频播放量总和
     * @param userId 用户id
     * @return
     */
    @Override
    public Integer videoIsreprintSum(Integer userId) {
        return videoMapper.videoIsreprintSum(userId,1);
    }

    /**
     * 查询用户被下架的视频
     * @param userId
     * @param videoTitle
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Map<String,Object>> videoSold(Integer userId, String videoTitle, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String,Object>> list = videoMapper.videoSold(userId, 0,videoTitle);
        PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Integer videoDelByVideoId(Integer videoId) {
        return videoMapper.videoDelByVideoId(videoId);
    }
}
